﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using NRemedy;
using Wicresoft.EKA.CIImportApp.Model;

namespace Wicresoft.EKA.CIImportApp.Init
{
    public static class DataInit
    {
        private static readonly string ARServer = ConfigurationManager.AppSettings["ARServer"];
        private static readonly string AdminName = ConfigurationManager.AppSettings["ARUid"];
        private static readonly string AdminPassword = ConfigurationManager.AppSettings["ARPwd"];

        public static bool ImportHardware(ASTBMC_Hardware model)
        {
            try
            {
                using (var arContext = new ARLoginContext(ARServer, AdminName, AdminPassword))
                {
                    ARProxy<ASTBMC_Hardware> ar = new ARProxy<ASTBMC_Hardware>(arContext);
                    ar.CreateEntry(model);
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
            
        }

        public static bool ImportAppSystem(ASTBMC_AppSystem model)
        {
            try
            {
                using (var arContext = new ARLoginContext(ARServer, AdminName, AdminPassword))
                {
                    ARProxy<ASTBMC_AppSystem> ar = new ARProxy<ASTBMC_AppSystem>(arContext);
                    ar.CreateEntry(model);
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }

        public static bool ImportSysSoftware(ASTBMC_SysSoftware model)
        {
            try
            {
                using (var arContext = new ARLoginContext(ARServer, AdminName, AdminPassword))
                {
                    ARProxy<ASTBMC_SysSoftware> ar = new ARProxy<ASTBMC_SysSoftware>(arContext);
                    ar.CreateEntry(model);
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
    }

}
